import django.dispatch
from apps.message.models import Messages_model
# action即为注册的信号名称
action=django.dispatch.Signal()


from django.db import transaction
from django.http import JsonResponse

@transaction.atomic
def pre_save_func(sender, **kwargs):
    try:
        Messages_model.objects.create(msg_deal_person_id=kwargs['to_user'],msg_launch_person_id=sender,msg_modular_from=2,msg_simple_text=kwargs['msg'],
                                  msg_detail_text=kwargs['xiangshu']
                                  )
    except Exception:
        raise JsonResponse({'msg':'消息模型数据添加失败！'})
action.connect(pre_save_func)